package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "订单模块")
@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 查询订单
     * @param dto
     * @return
     */
    @ApiOperation("查询订单")
    @GetMapping("/conditionSearch")
    public Result<PageResult> search(OrdersPageQueryDTO dto){
        log.info("查询订单：{}",dto);
        PageResult pageResult = orderService.page(dto);
        return Result.success(pageResult);

    }

    /**
     * 接单
     * @param dto
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result<String> confirm(@RequestBody OrdersConfirmDTO dto){
        log.info("接单：{}",dto);
        orderService.confirm(dto);
        return Result.success();
    }

    /**
     * 拒单
     * @param dto
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO dto){
        log.info("拒单：{}",dto);
        orderService.rejection(dto);
        return Result.success();
    }

    /**
     * 取消订单
     * @param dto
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result<String> cancel(@RequestBody OrdersCancelDTO dto){
        log.info("取消订单：{}",dto);
        orderService.adminCancel(dto);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result<String> delivery(@PathVariable Long id){
        log.info("派送订单：{}",id);
        orderService.delivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result<String> complete(@PathVariable Long id){
        log.info("完成订单：{}",id);
        orderService.complete(id);
        return Result.success();
    }

    /**
     * 查看订单详情
     * @param id
     * @return
     */
    @ApiOperation("查看订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id){
        log.info("查看订单详情：{}",id);
        OrderVO orderVO = orderService.getOrderVo(id);
        return Result.success(orderVO);
    }

    /**
     * 查看个订单状态
     * @return
     */
    @ApiOperation("查看个订单状态")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> status(){
        log.info("查看个订单状态");
        OrderStatisticsVO vo = orderService.status();
        return Result.success(vo);
    }
}
